package com.xyzwps.example.chain;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

public record MapChain<K, V>(Map<K, V> value) {

    public <K2> MapChain<K2, V> mapKeys(Function<K, K2> fn) {
        var map = new HashMap<K2, V>();
        this.value.forEach((k, v) -> {
            map.put(fn.apply(k), v);
        });
        return new MapChain<>(map);
    }

    public <V2> MapChain<K, V2> mapValues(Function<V, V2> fn) {
        var map = new HashMap<K, V2>();
        this.value.forEach((k, v) -> {
            map.put(k, fn.apply(v));
        });
        return new MapChain<>(map);
    }

    public CollectionChain<K> keys() {
        return new CollectionChain<>(value.keySet());
    }

    public CollectionChain<V> values() {
        return new CollectionChain<>(value.values());
    }

}
